// 引入express
const express = require("express");
// 引入数据库
const sql = require("../pool.js");
// 创建路由器对象
const route = express.Router();
// 活动内容增加路由
route.post("/activeAdd", (req, res) => {
	let date = new Date()
  sql.query("insert into zm_active set ? ,time=?", [req.body,date], (err,r) => {
    if (err) {
      throw err;
    }
    console.log(r);
	console.log(req.body)
  
  if (r.affectedRows) {
    res.send("增加成功!");
  } else {
    res.send("增加失败!");
  }
});
});
route.get("/activeQuery",(req,res)=>{
    // let pid = parseInt(req.params.pid)
    sql.query("select * from zm_active",(err,r)=>{
      if(err){
        throw err
      }
      if(r.length){
        res.send({code:200,msg:'查询成功',data:r})
      }else{
        res.send({code:400,msg:'查询失败'})
      }
    })
  })
  // 活动内容更改
route.put("/activeUpdate/:aid",(req,res)=>{
    let aid = parseInt(req.params.aid)
    sql.query("update zm_active set ? where zm_active.aid = ?",[req.body,aid],(err,r)=>{
      if(err){
        throw err
      }
      if(r.affectedRows){
        res.send("更改成功!")
      }else{
        res.send("更改失败!")
      }
    })
  })
module.exports = route